﻿using System;
using System.Collections;

namespace MediaRemoteServer
{
    public class Playlist
    {

        private ArrayList mrlList;
        private int currentlyPlaying;

        public Playlist()
        {
            mrlList = new ArrayList();
            mrlList.Capacity = 256;
            currentlyPlaying = -1;
        }

        public void addItem(string mrl)
        {
            if (mrlList.Count <= 256)
            {
                mrlList.Add(mrl);
            }
        }

        public void addItem(string mrl, int index)
        {
            if (mrlList.Count <= 256)
            {
                mrlList.Insert(index, mrl);
            }
        }

        public string next()
        {
            string mrl = null;

            if ((currentlyPlaying + 1) <= (mrlList.Count - 1))
            {
                mrl = (string)mrlList[++currentlyPlaying];
            }

            return mrl;
        }

        public string previous()
        {
            string mrl = null;

            if (currentlyPlaying > 0)
            {
                mrl = (string)mrlList[--currentlyPlaying];
            }

            return mrl;
        }

        public string current()
        {
            string mrl = null;

            if ((currentlyPlaying >= 0) && (currentlyPlaying < mrlList.Count))
            {
                mrl = (string)mrlList[currentlyPlaying];
            }

            return mrl;
        }

        public void remove(int index)
        {
            mrlList.RemoveAt(index);
        }

        public void remove(string mrl)
        {
            mrlList.Remove(mrl);
        }

    }
}
